<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审理员调整</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
    <style type="text/css">
        .layui-disabled, .layui-disabled:hover {
            color: #000000 !important;
            cursor: not-allowed !important;
        }

        .layui-form-label {
            width: 100px;
        }

        .layui-input-block {
            margin-left: 130px;
        }

        .layui-input layui-unselect {
            cursor: pointer;
        }

        .layui-table {
            width: 96%;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div class="layui-card-body">
                    <div class="layui-tab table_div">
                        <ul class="layui-tab-title">
                            <li class="layui-this" id="grdb">待调整审理人</li>
                            <li id="gryb">已调整审理人</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <form id="searchForm0">
                                    <div class="layui-input-inline">
                                        <label for="jcajbh0"></label>
                                        <input type="text" class="layui-input" id="jcajbh0"
                                               placeholder="请输入案件编号">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="nsrmc0"></label>
                                        <input type="text" class="layui-input" id="nsrmc0"
                                               placeholder="请输入纳税人名称">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="nsrsbh0"></label>
                                        <input type="text" class="layui-input" id="nsrsbh0"
                                               placeholder="请输入纳税人识别号">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="startTime0"></label>
                                        <input type="text" readonly class="layui-input" id="startTime0"
                                               placeholder="立案时间起">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="endTime0"></label>
                                        <input type="text" readonly class="layui-input" id="endTime0"
                                               placeholder="立案时间止">
                                    </div>
                                    <div class="layui-input-inline">
                                        <button type="button" class="layui-btn" onclick="grdbSearch()" id="search">
                                            查询
                                        </button>
                                        <button type="button" class="layui-btn" id="resetBtn0">重置</button>
                                        <button type="button" class="layui-btn" id="exportBtn0">导出</button>
                                    </div>
                                </form>
                                <table class="layui-table" id="grdbShowTable" lay-filter="grdbShowTable"></table>
                            </div>
                            <div class="layui-tab-item">
                                <form id="searchForm1">
                                    <div class="layui-input-inline">
                                        <label for="jcajbh1"></label>
                                        <input type="text" class="layui-input" id="jcajbh1"
                                               placeholder="请输入案件编号">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="nsrmc1"></label>
                                        <input type="text" class="layui-input" id="nsrmc1"
                                               placeholder="请输入纳税人名称">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="nsrsbh1"></label>
                                        <input type="text" class="layui-input" id="nsrsbh1"
                                               placeholder="请输入纳税人识别号">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="startTime1"></label>
                                        <input type="text" readonly class="layui-input" id="startTime1"
                                               placeholder="立案时间起">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="endTime1"></label>
                                        <input type="text" readonly class="layui-input" id="endTime1"
                                               placeholder="立案时间止">
                                    </div>
                                    <div class="layui-input-inline">
                                        <button type="button" class="layui-btn" onclick="grybSearch()" id="search1">
                                            查询
                                        </button>
                                        <button type="button" class="layui-btn" id="resetBtn1">重置</button>
                                        <button type="button" class="layui-btn" id="exportBtn1">导出</button>
                                    </div>
                                </form>
                                <table class="layui-table" id="grybShowTable" lay-filter="grybShowTable"></table>
                            </div>
                        </div>
                    </div>
                    <!--选择调查人下拉选-->
                    <div id="debugtaxorgDiv" class="demo-transfer" style="display: none">
                        <div class="layui-form">
                            <!-- 协查人 -->
                            <div class="layui-form-item" style="margin-top: 40px">
                                <label class="layui-form-label">选择审理人</label>
                                <div class="layui-input-block">
                                    <label for="slrSelect"></label>
                                    <select name="slrSelect" xm-select="slrSelect" xm-select-skin="primary"
                                            lay-filter="slrSelect"
                                            id="slrSelect" multiple>
                                        <option value="">选择审理人</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="grdbTool">
    <a class="layui-btn layui-btn-xs" lay-event="view">调整</a>
</script>


<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script src="/layui/formSelects-v3.js"></script>
<script th:inline="none">
    // 获取token
    var token = CoreUtil.getData("access_token");
    // 地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var grdbTableIns;
    var grybTableIns;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var upload = layui.upload;
    var element = layui.element;
    var maxlength = 500;
    var debugtaxman = "";
    var formSelects = layui.formSelects;
    var meetMan = "";
    layui.use(['table', 'layer', 'laydate', 'upload', 'element'], function () {
        // 个人待办
        grdbTableIns = table.render({
            elem: '#grdbShowTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            page: true // 开启分页
            ,
            url: '/workflow/hear/querySlytzPage' //数据接口
            ,
            method: 'POST',
            where: {
                sllx: "0"
            },
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null
                        : CoreUtil.paramsDecrypt(res.data.records)
                }
            },
            cols: [[
                {
                    align: 'center',
                    width: 230,
                    field: 'jcajxxuuid',
                    title: '检查UUID',
                    sort: true,
                    hide: true
                }, {
                    align: 'center',
                    width: 200,
                    field: 'jcajbh',
                    title: '检查案件编号',
                    sort: true,
                },
                // {
                //     align: 'center',
                //     width: 260,
                //     field: 'ajmc',
                //     title: '案件名称',
                //     sort: true,
                // },
                {
                    align: 'center',
                    width: 140,
                    field: 'ajztmc',
                    title: '系统状态',
                    sort: true,
                }, {
                    align: 'center',
                    width: 180,
                    field: 'slry',
                    title: '检查人员',
                    sort: true,
                }, {
                    align: 'center',
                    width: 160,
                    field: 'jcxm',
                    title: '检查项目',
                    sort: true,
                }, {
                    align: 'center',
                    width: 300,
                    field: 'nsrmc',
                    title: '纳税人名称',
                    sort: true,
                }, {
                    align: 'center',
                    width: 200,
                    field: 'nsrsbh',
                    title: '纳税人识别号',
                    sort: true,
                }, {
                    align: 'center', width: 150, field: 'larq', title: '立案时间', sort: true, templet: function (d) {
                        // 格式化日期为 'yyyy-MM-dd'
                        return layui.util.toDateString(d.larq, 'yyyy-MM-dd');
                    }
                }, {
                    fixed: 'right',
                    align: 'center',
                    width: 75,
                    toolbar: "#grdbTool",
                    title: '操作'
                }

            ]],
            toolbar: '#grdbToolbar'
        });
        // 个人已办
        grybTableIns = table.render({
            elem: '#grybShowTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            page: true // 开启分页
            ,
            url: '/workflow/hear/querySlytzPage' //数据接口
            ,
            method: 'POST',
            where: {
                sllx: "1"
            },
            parseData: function (res1) { //将原始数据解析成 table 组件所规定的数据
                console.log("res:", res1.data)
                return {
                    "code": res1.code, //解析接口状态
                    "msg": res1.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res1.data) ? 0 : res1.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res1.data) ? null
                        : CoreUtil.paramsDecrypt(res1.data.records)
                }
            },
            cols: [[
                {
                    align: 'center',
                    width: 230,
                    field: 'jcajxxuuid',
                    title: '检查UUID',
                    sort: true,
                    hide: true
                }, {
                    align: 'center',
                    width: 200,
                    field: 'jcajbh',
                    title: '检查案件编号',
                    sort: true,
                },
                // {
                //     align: 'center',
                //     width: 200,
                //     field: 'ajmc',
                //     title: '案件名称',
                //     sort: true,
                // },
                {
                    align: 'center',
                    width: 180,
                    field: 'slry',
                    title: '原审理人',
                    sort: true,
                }, {
                    align: 'center',
                    width: 300,
                    field: 'sjslr',
                    title: '现审理人',
                    sort: true,
                },
                // {
                //     align: 'center',
                //     width: 328,
                //     field: 'content',
                //     title: '调整原因',
                //     sort: true,
                // },
                {
                    align: 'center',
                    width: 180,
                    field: 'jcry',
                    title: '检查人员',
                    sort: true,
                }, {
                    align: 'center',
                    width: 150,
                    field: 'jcxm',
                    title: '检查项目',
                    sort: true,
                }, {
                    align: 'center',
                    width: 280,
                    field: 'nsrmc',
                    title: '纳税人名称',
                    sort: true,
                }, {
                    align: 'center',
                    width: 200,
                    field: 'nsrsbh',
                    title: '纳税人识别号',
                    sort: true,
                }, {
                    align: 'center', width: 150, field: 'larq', title: '立案时间', sort: true, templet: function (d) {
                        // 格式化日期为 'yyyy-MM-dd'
                        return layui.util.toDateString(d.larq, 'yyyy-MM-dd');
                    }
                }, {
                    fixed: 'right',
                    align: 'center',
                    width: 75,
                    toolbar: "#grdbTool",
                    title: '操作'
                }
            ]],
            toolbar: '#grdbToolbar'
        });

        // 个人待办表头工具
        table.on('grdbToolbar(grdbShowTable)', function (obj) {
            switch (obj.event) {
            }
        });

        // 个人已办表头工具
        table.on('grybToolbar(grybShowTable)', function (obj) {
            switch (obj.event) {
            }
        });

        // 列操作
        table.on('tool(grdbShowTable)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'view':
                    /* lock(data); */
                    view(data, "0");
                    break;
            }
        });

        // 个人已办操作
        table.on('tool(grybShowTable)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'view':
                    view(data, "1");
                    break;
            }
        });

        $("#grdb").click(function () {
            grdbSearch();
        });

        $("#gryb").click(function () {
            grybSearch();
        });

        //调整-检查人
        table.on('tool(grdbShowTable)', function (obj) {
            openAdjustTaxOrgModal(obj);
        });
        table.on('tool(grybShowTable)', function (obj) {
            openAdjustTaxOrgModal(obj);
        });

        function openAdjustTaxOrgModal(obj) {
            console.log("obj.data:", obj.data)
            CoreUtil.sendPost("/workflow/activity/querySelectJcr", obj.data.jcbmDm, function (res) {
                if (res.code == '0') {
                    let value = res.data;
                    let opt = "<option value = ''>请选择审理员</option>";
                    for (let i in value) {
                        opt += '<option value = "' + value[i].swryxm + '">' + value[i].swryxm + '</option>';
                    }
                    $("#zcrSelect").html(opt);
                    $("#slrSelect").html(opt);
                    form.render('select'); //需要渲染一下
                    formSelects.render('slrSelect'); //渲染多选框
                } else {
                    layer.msg(res.msg);
                    return false;
                }
            });
            // 弹窗逻辑
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "调整检察人员",
                area: ['700px', '420px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#debugtaxorgDiv"),
                btn: ['调整审理人员', '取消'],
                yes: function (index) {
                    // 获取两个下拉框的值
                    obj.data.selectedValue = $('#zcrSelect').val(); // 主查人下拉框值
                    // 获取协查人下拉框中所有选中的值
                    obj.data.xcSelectedValue = layui.formSelects.value('slrSelect', 'val'); // 'slrSelect' 是 xm-select 的值
                    // 调用保存接口
                    CoreUtil.sendPost("/workflow/activity/saveSly", obj.data, function (res) {
                        if (res.code == '0') {
                            layer.msg("调整审理员成功！");
                            grdbSearch(); // 重新加载数据
                            grybSearch(); // 重新加载数据
                        } else {
                            layer.msg(res.msg);
                        }
                    });
                    layer.close(index); // 关闭弹窗
                },
                // 在弹窗打开时设置协查人的默认值
                success: function () {
                    // 设置协查人多选下拉框的默认选中的值
                    layui.formSelects.value('zcrSelect', $('#zcrSelect').val());
                    layui.formSelects.value('slrSelect', layui.formSelects.value('slrSelect', 'val'));
                }
            });
        }

        // 监听重置按钮
        document.getElementById('resetBtn0').addEventListener('click', function () {
            document.getElementById('searchForm0').reset(); // 原生重置表单
            form.render(); // 重新渲染 Layui 的动态组件
        });
        // 监听重置按钮
        document.getElementById('resetBtn1').addEventListener('click', function () {
            document.getElementById('searchForm1').reset(); // 原生重置表单
            form.render(); // 重新渲染 Layui 的动态组件
        });

        //立案时间起
        laydate.render({
            elem: '#startTime0'
            , type: 'date'
            , value: null
            , done: function (value) {
                if (value !== null && value !== undefined && value !== "") {
                    startTime = value;
                } else {
                    startTime = null;
                }
            }
        });
        //立案时间止
        laydate.render({
            elem: '#endTime0'
            , type: 'date'
            , value: null
            , done: function (value) {
                if (value !== null && value !== undefined && value !== "") {
                    endTime = value;
                } else {
                    endTime = null;
                }
            }
        });
        //立案时间起
        laydate.render({
            elem: '#startTime1'
            , type: 'date'
            , value: null
            , done: function (value) {
                if (value !== null && value !== undefined && value !== "") {
                    startTime = value;
                } else {
                    startTime = null;
                }
            }
        });
        //立案时间止
        laydate.render({
            elem: '#endTime1'
            , type: 'date'
            , value: null
            , done: function (value) {
                if (value !== null && value !== undefined && value !== "") {
                    endTime = value;
                } else {
                    endTime = null;
                }
            }
        });

        // 未调整点击导出按钮
        $("#exportBtn0").click(function () {
            layer.confirm('确定导出所有数据?', {icon: 3, title: '提示'}, function (index) {
                const mapArr = {
                    jcajbh: $("#jcajbh0").val(),
                    nsrmc: $("#nsrmc0").val(),
                    nsrsbh: $("#nsrsbh0").val(),
                    lasjq: $("#startTime0").val(),
                    lasjz: $("#endTime0").val(),
                    sllx: "0"
                };
                CoreUtil.sendPost("/workflow/inspect/exportSly", mapArr, function (res) {
                    if (res.code == '0') {
                        const data = res.data;
                        if (!CoreUtil.isEmpty(data)) {
                            //全部导出
                            table.exportFile(grdbTableIns.config.id, data, 'xls');
                            //导出时阻止页面刷新
                            $(".layui-form").submit(function (e) {
                                e.preventDefault();
                            })
                        } else {
                            layer.alert('未查询到需要导出的数据！', {icon: 2});
                        }
                    }
                });
                layer.close(index);
            });
        });

        // 已调整点击导出按钮
        $("#exportBtn1").click(function () {
            layer.confirm('确定导出所有数据?', {icon: 3, title: '提示'}, function (index) {
                const mapArr = {
                    jcajbh: $("#jcajbh1").val(),
                    nsrmc: $("#nsrmc1").val(),
                    nsrsbh: $("#nsrsbh1").val(),
                    lasjq: $("#startTime1").val(),
                    lasjz: $("#endTime1").val(),
                    sllx: "1",
                };
                CoreUtil.sendPost("/workflow/inspect/exportSly", mapArr, function (res1) {
                    if (res1.code == '0') {
                        const data = res1.data;
                        if (!CoreUtil.isEmpty(data)) {
                            //全部导出
                            table.exportFile(grybTableIns.config.id, data, 'xls');
                            //导出时阻止页面刷新
                            $(".layui-form").submit(function (e) {
                                e.preventDefault();
                            })
                        } else {
                            layer.alert('未查询到需要导出的数据！', {icon: 2});
                        }
                    }
                });
                layer.close(index);
            });
        });
    });

    // 个人待办执行查询
    function grdbSearch() {
        const jcajbh = $("#jcajbh0").val();
        const nsrmc = $("#nsrmc0").val();
        const nsrsbh = $("#nsrsbh0").val();
        const startTime = $("#startTime0").val();
        const endTime = $("#endTime0").val();
        grdbTableIns.reload({
            where: {
                jcajbh: jcajbh,
                nsrmc: nsrmc,
                nsrsbh: nsrsbh,
                lasjq: startTime,
                lasjz: endTime
            },
            page: {
                curr: 1
            }
        });
    }

    // 个人已办执行查询
    function grybSearch() {
        const jcajbh = $("#jcajbh1").val();
        const nsrmc = $("#nsrmc1").val();
        const nsrsbh = $("#nsrsbh1").val();
        const startTime = $("#startTime1").val();
        const endTime = $("#endTime1").val();
        grybTableIns.reload({
            where: {
                jcajbh: jcajbh,
                nsrmc: nsrmc,
                nsrsbh: nsrsbh,
                lasjq: startTime,
                lasjz: endTime
            },
            page: {
                curr: 1
            }
        });
    }


</script>

</body>
</html>